// index.js
const {request} = require('../../utils/util.js')
Component({
  data: {
    title: wx.getStorageSync('sysname')+"-实时出勤",
    total:0,
    total_cars:0,
    value:0,
    djs:[],
    zjs:[]
  },
  methods: {
    onLoad() {
      wx.showLoading({
        title: '加载中',
      })
      this.getData();
      //设置定时加载数据
      setInterval(()=>{
        this.getData();
      },10000)
    },
    onTabsChange(event) {
      console.log(`Change tab, tab-panel value is ${event.detail.value}.`);
      this.setData({
        value: event.detail.value
      })
    },
    getData(){
      let that = this

      request('GET', 'api.VehicleData/getLive', {}).then(res => {
        console.log("getData",res)
        if(res.code==1){
          let data = res.data
          that.setData({
            zjs:data.zjs,
            djs:data.djs,
            total:data.total,
            total_cars:data.total_cars
          })
        }else{
          wx.showToast({
            title: res.info,
            icon: 'none',
            duration: 2000
          })
        }
        wx.hideLoading()
      }).catch(err => {
        console.error('Error:', err);
      });
    }
  },
})
